#ifndef FIELD_H
#define FIELD_H

#include <QObject>
#include <QSize>
#include <QPoint>
#include <QVector>
#include <QSharedPointer>
#include <QGraphicsObject>
#include <QGraphicsScene>

class Ball;

class Field : public QGraphicsScene
{
	Q_OBJECT

	friend class FieldBuilder;

	const static QSharedPointer<QGraphicsObject> OUT_OF_FIELD;
	const static QSharedPointer<QGraphicsObject> EMPTY_CELL;

	QVector< QVector< QSharedPointer<QGraphicsObject> > > field;

	QSize size;
	int ballsNumber;
	QPoint cellToClear;

	void addCell(const QPoint& cell);
	void addBall(const QPoint& cell, QSharedPointer<QGraphicsObject> ball);
	void clearCell(const QPoint& cell);
	void moveBall(const QPoint& from, const QPoint& to);

public:
	Field(QSize size, QObject *parent = 0);
	QSize getSize() const;
	bool isEmptyCell(const QPoint &cell) const;
	bool makeMove(const QPoint& from, const QPoint& to);
	bool isPointOnField(const QPoint &point) const;
	bool isBusyCell(const QPoint& cell) const;
	int ballsRemains() const;

	
signals:
	
public slots:
	void ballMoved(const QPointF &from, const QPointF &to, Ball *ball);
	void removeAnimationFinished();
};

#endif // FIELD_H
